<!--
    Powered By nodePPT - This is probably the best web presentation tool so far!
    version: 0.9.8-3
    site: https://github.com/ksky521/nodePPT
-->
<!doctype html>
<html>
<head>
    <meta charset="UTF-8">
    <title>python_07_数据库 - By woniuppp</title>
    <link rel="stylesheet" media="all" href="./css/nodeppt2.0.css">
    <link rel="stylesheet" media="only screen and (max-device-width: 480px)" href="./css/phone.css">
    <link rel="stylesheet" media="print" href="./css/pdf.css">
    <link rel="stylesheet" href="./js/highlight/styles/monokai_sublime.css">
    <link rel="stylesheet" href="./css/font-awesome.css">
</head>
<body>
<div class="slides">
    <slides id="container">
        <slide class="slide"><section class="slide-wrapper"><article class="flexbox vcenter">
<h1>python基础教程<em>07</em>数据库</h1>
<p><small>woniuppp</small></p>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾</h2>

</hgroup><article>

<ul>
<li>变量</li>
<li>逻辑判断</li>
<li>循环</li>
<li>list</li>
<li>字符串</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾</h2>

</hgroup><article>

<ul>
<li>dict</li>
<li>函数</li>
<li>文件</li>
<li>前端基础</li>
<li>模块</li>
<li>flask</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——语句和逻辑判断</h2>

</hgroup><article>

<ul>
<li>变量</li>
<li>if else</li>
<li>for while</li>
<li>break continue</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——list</h2>

</hgroup><article>

<ul>
<li>定义list</li>
<li>遍历</li>
<li>删除</li>
<li>取值</li>
<li>list的方法</li>
<li>元组</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——dict</h2>

</hgroup><article>

<ul>
<li>字典是什么</li>
<li>取值</li>
<li>遍历</li>
<li>删除</li>
<li>dict的方法</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——字符串</h2>

</hgroup><article>

<ul>
<li>定义</li>
<li>切片</li>
<li>切割</li>
<li>查找</li>
<li>替换</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——文件操作</h2>

</hgroup><article>

<ul>
<li>打开文件</li>
<li>读文件</li>
<li>写文件</li>
<li>关闭文件</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——前端基础</h2>

</hgroup><article>

<ul>
<li>html常用标签</li>
<li>css作用及常用属性</li>
<li>javascript</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——函数</h2>

</hgroup><article>

<ul>
<li>函数创建</li>
<li>返回值</li>
<li>参数</li>
<li>作用域</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>期中回顾——模块</h2>

</hgroup><article>

<ul>
<li>模块的定义</li>
<li>模块的使用</li>
<li>python自带模块</li>
<li>第三方模块</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>我们现在能做什么</h2>

</hgroup><article>

<ul>
<li>nginx日志分析<ul>
<li>文件操作，list和dict操作，排序</li>
</ul>
</li>
<li>基于文件存储的简单的管理<ul>
<li>前端页面</li>
<li>flask接受参数</li>
<li>存储文件</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>上节练习</h2>

</hgroup><article>

<ul>
<li>计算器，要求优先级<ul>
<li>思路</li>
</ul>
</li>
<li>存储文件，可以增加和查看用户和年龄<ul>
<li>思路</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>整体web介绍</h2>

</hgroup><article>

<ul>
<li>前端web页面</li>
<li>flask接受前端参数</li>
<li>对数据库进行操作</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>数据库</h2>
<h3>存储数据</h3>

</hgroup><article>

<ul>
<li>流行的数据库<ul>
<li>mysql</li>
<li>oracle</li>
<li>sql server</li>
<li>sqlite</li>
<li>等等</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>sql</h2>
<h3>数据库各有特点，sql都是通用的</h3>

</hgroup><article>

<ul>
<li>神马是sql<ul>
<li>操作数据库</li>
</ul>
</li>
<li>数据库都有什么概念</li>
<li>都有什么操作<ul>
<li>增加数据</li>
<li>删除数据</li>
<li>修改数据</li>
<li>查询</li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>数据库里的概念</h2>
<h3>一个数据库里有很多表，表是我们操作的主要对象</h3>

</hgroup><article>

<ul>
<li>数据库<ul>
<li>需要密码</li>
</ul>
</li>
<li>表<ul>
<li>类似于excel表格
<img src="../07/table.png" alt=""></li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>进入数据库</h2>

</hgroup><article>

<pre><code class="sql">
    mysql -u reboot -preboot123
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>查看和选择数据库</h2>

</hgroup><article>

<ul>
<li><p>查看所有数据库</p>
<pre><code class="sql">
  show databases
</code></pre></li>
<li><p>新建数据库</p>
<pre><code class="sql">
  create database test
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>查看和选择数据库</h2>

</hgroup><article>

<ul>
<li>使用test数据库<pre><code class="sql">
  use test;
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>表格--存储数据</h2>

</hgroup><article>

<ul>
<li>新建表格<pre><code class="sql">
CREATE TABLE 表名称
(
列名称1 数据类型,
列名称2 数据类型,
列名称3 数据类型,
....
)    
create table user (name varchar(255),age int);
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>表</h2>

</hgroup><article>

<ul>
<li>查看表结构<pre><code class="sql">
  desc user;
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>插入数据</h2>

</hgroup><article>

<ul>
<li>insert语句 插入数据<pre><code class="sql">
INSERT INTO 表名称 VALUES (值1, 值2,....)
insert into user values ('wd',18);
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>查询数据(重要)</h2>

</hgroup><article>

<ul>
<li>select语句 查询数据<pre><code class="sql">
SELECT 列名称 FROM 表名称
SELECT * FROM 表名称
select * from user;
select age from user;
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>update 修改数据</h2>

</hgroup><article>

<ul>
<li>修改年龄<pre><code class="sql">
UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值
update user set age=100 where name='wd';
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>delete 删除</h2>

</hgroup><article>

<ul>
<li>删除name是wd的数据<pre><code class="sql">
DELETE FROM 表名称 WHERE 列名称 = 值
delete from user where name='wd';
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>select进阶</h2>

</hgroup><article>

<ul>
<li>where 限制查询结果<pre><code class="sql">
  select 字段 from 表名 where 列名称 操作符 值
  select * from user where name='wd';
  select * from user where age>30;
</code></pre></li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>and or 多条件查询</h2>
<pre><code class="sql">
    select * from user where age>30 and age<40;
    select * from user where name='wd' or name='pc';

</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><article>
<h2>删除表格</h2>
<pre><code class="sql">
    DROP TABLE 表名称
</code></pre>
</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>sql复习</h2>

</hgroup><article>

<ul>
<li>增</li>
<li>删</li>
<li>改</li>
<li>查</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>python的MySQLdb模块</h2>

</hgroup><article>

<ul>
<li>连接数据库并且查询
<pre><code class="python">
import MySQLdb
db = mysql.connect(user=&quot;reboot&quot;, passwd=&quot;reboot123&quot;, \
      db=&quot;test&quot;, charset=&quot;utf8&quot;)
cur = db.cursor()
cur.execute(&#39;select * from user&#39;)</li>
</ul>
<p>for c in cur.fetchall():
    print &#39;name is %s and age is %d&#39; % c
</code></pre></p>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>小练习</h2>

</hgroup><article>

<ul>
<li>上次作业的存储，换成mysql数据库</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>小练习</h2>

</hgroup><article>

<ul>
<li>处理nginx的日志，存储mysql</li>
<li>前端用jquery异步调用接口，展现log分析结果</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>前端教程推荐</h2>

</hgroup><article>

<ul>
<li>html<ul>
<li><a href="http://www.w3school.com.cn/html/index.asp" target="_blank">http://www.w3school.com.cn/html/index.asp</a></li>
</ul>
</li>
<li>css<ul>
<li><a href="http://www.w3school.com.cn/css/index.asp" target="_blank">http://www.w3school.com.cn/css/index.asp</a></li>
</ul>
</li>
<li>jquery<ul>
<li><a href="http://www.w3school.com.cn/jquery/index.asp" target="_blank">http://www.w3school.com.cn/jquery/index.asp</a></li>
</ul>
</li>
</ul>

</article></section></slide>
<slide class="slide"><section class="slide-wrapper"><hgroup>
<h2>微信公众号</h2>

</hgroup><article>

<p><img src="./logo.jpg" alt="reboot" title="reboot"></p>

</article></section></slide>
        <slide class="slide thank-you-slide segue nobackground">
            <article class="flexbox vleft auto-fadein">
                <h2>Q &amp; A</h2>
                <h3>&lt;Thank You!&gt;</h3>
            </article>
        </slide>
        <slide class="slide logoslide dark nobackground">
            <article class="flexbox vcenter">
              <h2 style="color: white;">Powered By nodePPT v0.9.8-3</h2>
            </article>
          </slide>
        <div class="slideTip" id="tip"></div>
    </slides>
</div>
<canvas id="drawBoard" class="draw-board" width="900" height="700"></canvas>
<div class="progress"><span id="progress"></span></div>
<div id="_buttons">
    <div class="_btn-box" id="_btn-box" style="display:none;">
        <button class="fa fa-arrow-circle-left" id="_btn-prev"></button>
        <button class="fa fa-arrow-circle-right" id="_btn-next"></button>
        <button class="fa fa-paint-brush" id="_btn-brush"></button>
        <button class="fa fa-compress" id="_btn-overview" data-toggle="fa fa-expand"></button>
    </div>
    <button class="fa fa-bars" id="_btn-bar"  data-toggle="fa fa-close"></button>
</div>
<script src="./js/mixjs/lib/mix.0.3.0.min.js"></script>
<script>
var base = location.protocol + '//' + location.host;

var path = location.pathname.split('/').filter(function(v){
    return !!v;
});
path.pop();
path = path.join('/');
MixJS.config({
    baseURL: [ base, path, 'js'].join('/')+'/'
});

</script>
<script src="./js/mixjs/lib/event/broadcast.js"></script>
<script src="./js/nodeppt.js"></script>
<script>
Slide.init({
    containerID: 'container',
    drawBoardID: 'drawBoard',
    slideClass: '.slide',
    buildClass: '.build',
    progressID: 'progress',
    transition: 'slide',
    width: 1100,
    dir: './',
    
    //打开下面的注释就开启postMessage方式
    //访问网址127.0.0.1:8080/ppt/demo#client
    control:{
        type: 'postMessage',
        args:{
            isControl:  false
        }
    },
    
    tipID: 'tip'
});
MixJS.loadJS('highlight/hljs-0.8.js',function(){
    hljs.tabReplace = '  ';
    hljs.initHighlightingOnLoad();
});
</script>
<script src="./js/demo.js"></script>
<link rel="stylesheet" href="./css/demo.css">
</body>
</html>
